package com.example.thirdhomework

import android.app.Activity
import android.content.Intent
import android.graphics.Bitmap
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.example.thirdhomework.databinding.ActivityMainBinding
import java.io.Serializable


const val KEY1="key1"
const val KEY2="key2"
data class Person(val name: String, val age: Int): Serializable
data class Student(val name: String, val age: Int, val teacher: Person): Serializable
class MainActivity : AppCompatActivity() {
    private lateinit var binding: ActivityMainBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        binding.button1.setOnClickListener {
            val intent = Intent(this, FirstActivity::class.java)
            val student = Student(binding.editTextText.text.toString(), 20 , Person("Tom", 30))
            intent.putExtra(KEY1, student)
            startActivity(intent)
        }
        binding.button2.setOnClickListener {
            val intent = Intent(this, SecondActivity::class.java)
            startActivityForResult(intent,1)

        }
        binding.button3.setOnClickListener {
//            dispatchTakePictureIntent()
            val intent = Intent(this, ThirdActivity::class.java)
            startActivity(intent)
        }
        binding.button4.setOnClickListener {
            val intent = Intent(this, ForthActivity::class.java)
            startActivity(intent)
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == 1) {
            if (resultCode == 1) {
                val text = data?.getStringExtra(KEY2)
                binding.textView2.text = text
            }
        }
    }

}
